/*
 * ComparisonVertex.java
 *
 * Created on August 23, 2007, 2:25 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package dnbW.queryW.visualW;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 *
 * @author zhouyong
 */
public class ComparisonVertex extends PathOrientedVertex{
    
    private String _operator;
    private String _value;
    
    public static final String GT = ">";
    public static final String LT = "<";
    public static final String GTE = ">=";
    public static final String LTE = "<=";
    public static final String EQ = "=";
    
    public static final String[] OPS = {
        "=",
        "!=",
        ">",
        "<",
        ">=",
        "<=",
        "Like",
        "Not Like",
        "Between"
    };
    
    /** Creates a new instance of ComparisonVertex */
    public ComparisonVertex(
            DefaultMutableTreeNode node,
            String operator,
            String value) {
        super(node);
        setOperator(operator);
        setValue(value);
    }
    
    @Override
    public String getPredicateExpression() {
        if("!=".equals(getOperator()) || "=".equals(getOperator()))
            return "(" + this.toString() + " " + getOperator() + " \"" + getValue() + "\")";
        else
            return "(" + this.toString() + " " + getOperator() + " " + getValue() + ")";
    }
    
    @Override
    public String getHumanReadableText() {
        if(!EQ.equals(getOperator()))
            return this.getXPath() + " " + getOperator() + " " + getValue();
        else
            return this.getXPath() + " " + getOperator() + " \"" + getValue() + "\"";
    }
    
    public DefaultMutableTreeNode getNode() {
        return _path.get(_path.size() - 1);
    }
    
    public String getOperator() {
        return _operator;
    }
    
    public void setOperator(String operator) {
        this._operator = operator;
    }
    
    public String getValue() {
        return _value;
    }
    
    public void setValue(String value) {
        this._value = value;
    }
    
    public List<List<PredicateVertex>> getPredicateList(){
        
        List<PredicateVertex> l1 = new ArrayList<PredicateVertex>();
        l1.add(this);
        
        List<List<PredicateVertex>> l2 = new ArrayList<List<PredicateVertex>>();
        l2.add(l1);
        
        return l2;
    }

    @Override
    public Map<Integer, Long> getIdentityPathMapFinal() {
        return new TreeMap<Integer, Long>(this.getIdentityPathMap());
    }
    
    
}
